package pres.liko.iot.api;

import org.springframework.web.bind.annotation.*;
import reactivefeign.spring.config.ReactiveFeignClient;
import reactor.core.publisher.Mono;

import java.util.Map;
import java.util.Set;

/**
 * @ClassName: CacheOpenfrignClient
 * @Auther: liko
 * @Description:
 * @Date: 2022/11/1 08:58
 */
@ReactiveFeignClient("iot-cache")
public interface CacheOpenfrignClient {
    /**
     * String 设置String类型
     *
     * @param key
     * @param value
     * @return
     */
    @PostMapping("/cache/string/set/{key}/{value}")
    public Mono<Boolean> set(@PathVariable String key, @PathVariable String value);

    /**
     * String 根据key获取值
     *
     * @param key
     * @return
     */
    @PostMapping("/cache/string/get/{key}")
    public Mono<String> get(@PathVariable String key);

    /**
     * String 设置过期时间
     *
     * @param key
     * @param value
     * @param expireTime
     * @return
     */
    @PostMapping("/cache/string/set/{key}/{value}/{expireTime}")
    public Mono<Boolean> setValueWithExp(@PathVariable String key, @PathVariable String value, @PathVariable Long expireTime);

    /**
     * Srting 自增带步长
     *
     * @param key
     * @param step
     * @return
     */
    @GetMapping("/cache/string/get/{key}/{step}")
    public Mono<Long> incrementBy(@PathVariable String key, @PathVariable Long step);

    /**
     * String 只有当前key不存在的时候设置值
     *
     * @param key
     * @param value
     * @return
     */
    @PostMapping("/cache/string/nx/{key}/{value}")
    Mono<Boolean> setNx(@PathVariable String key, @PathVariable String value);

    @PostMapping("/cache/hash/{key}/{fieId}/{value}")
    Mono<Boolean> hSet(@PathVariable String key, @PathVariable String fieId, @PathVariable String value);

    @PostMapping("/cache/hash/{key}")
    Mono<Boolean> hMset(@PathVariable String key, @RequestBody Map values);

    @GetMapping("/cache/hash/{key}")
    Mono<Map> gGetAll(@PathVariable String key);

    @PostMapping("/cache/set/{key}/{member}")
    Mono<Long> sAdd(@PathVariable String key, @PathVariable String member);

    @PostMapping("/cache/sets/{key}")
    Mono<Long> sAddMembers(@PathVariable String key, @RequestBody Set<String> members);

    @GetMapping("/cache/set/{key}")
    Mono<Set<String>> sget(@PathVariable String key);

    @DeleteMapping("/cache/set/delete")
    Mono<Long> deleteKeys(@RequestBody String... keys);

    @PostMapping("/setmember/{key}/{value}")
    Mono<Boolean> sIsMember(@PathVariable String key, @PathVariable String value);
}
